#include <iostream>
#include <set>
#include <vector>
#include <iterator>
#include <vector>
#include <thread>
#include <sw/redis++/redis++.h>

using namespace std;
using namespace sw::redis;

void test(Redis &redis)
{
    cout << "zadd " << endl;

    redis.flushall();

    long long res = redis.zadd("key", {pair{"aaa", 111}, {"bbb", 222}, {"ccc", 333}, {"卢布", 78}});
    cout << "zadd: " << res << endl;

    vector<string> members;
    auto it1 = std::back_inserter(members);
    redis.zrange("key", 0, -1, it1);
    for (auto item : members)
        cout << "member: " << item << endl;

    vector<pair<string, double>> results;
    auto it2 = std::back_inserter(results);
    redis.zrange("key", 0, -1, it2);
    for (const auto &item : results)
        cout << "member: " << item.first << "   score: " << item.second << endl;
}

void test1(Redis &redis)
{
    cout << "zscore and zrank" << endl;

    redis.flushall();

    long long res = redis.zadd("key", {pair{"aaa", 111}, {"bbb", 222}, {"ccc", 333}, {"卢布", 78}});
    cout << "zadd: " << res << endl;

    auto score = redis.zscore("key", "ccc");
    if (score)
    {
        cout << "score: " << score.value() << endl;
    }
    auto rank = redis.zrank("key", "bbb");
    if (rank)
    {
        cout << "ramk: " << rank.value() << endl;
    }
}

void test2(Redis &redis)
{
    cout << "zscrd and zcount" << endl;

    redis.flushall();

    long long res = redis.zadd("key", {pair{"aaa", 111}, {"bbb", 222}, {"ccc", 333}, {"卢布", 78}});
    cout << "zadd: " << res << endl;

    res = redis.zcard("key");
    cout << "zscrd: " << res << endl; 

}

int main()
{
    Redis redis("tcp://127.0.0.1:6379");
    test2(redis);
    return 0;
}